<?php
include("utils.php");


 if($_SESSION['siteuserId']=="")
{
	header("location:index.php");
}

main_content("main();");
function main()
{
	if($_SESSION['languageId']!="")
{
	$languageId=$_SESSION['languageId'];
}
else
{
	$languageId='1';
}
	
	$siteUserId=$_SESSION['siteuserId'];

	$selSiteurl=mysql_query("select * from adsite_master where siteuserId='".$siteUserId."'");
	
	if(isset($_POST['next']))
	{
	
	$_SESSION['adspace_type'] = $_POST['adspace_type'];
//echo $_SESSION['adspace_type'];

if($_POST['ad_Type']=='network')
		{
			$netVal='Y';
		}
		else
		{
			$netVal='N';
		}

$_SESSION['netVal'] = $netVal;

	$insertAdMaster="insert into adspace_master set adsiteId='".$_POST['site_id']."', UserId='".$siteUserId."', langId='".$languageId."'";
	//echo $insertAdMaster;
	$exeAdmaster = mysql_query($insertAdMaster);
	$adspaceId = mysql_insert_id();	

	$md_no=md5($adspaceId);
	$updateAdMaster=mysql_query("update adspace_master set adspaceIdMd='".$md_no."' where adspaceId='".$adspaceId."' ");

	$insertAd = "insert into adspace_details set adspaceId='".$adspaceId."',adspaceIdMd='".$md_no."', adspaceType='".$_POST['adspace_type']."',adSize='".$_POST['size']."',fontSize='".$_POST['broker_link_font_size']."',fontType='".$_POST['broker_link_font_type']."', color='".$_POST['broker_link_font_color']."' ,hide_link='".$_POST['broker_link_hide']."',attribute='".$_POST['']."',backgroundColor='".$_POST['background_color']."',spaceDetails='".$_POST['broker_link_text_content']."',headerFontType='".$_POST['header_font_type']."',headerColor='".$_POST['header_bg_color']."',bodyFontType='".$_POST['body_font_type']."',bodyColor='".$_POST['body_bg_color']."',align='".$_POST['broker_link_align ']."', allowNetwork='".$netVal."' ";
	//echo $insertAd;
	$exeinsertAd = mysql_query($insertAd);
	$_SESSION['adspaceId']=$adspaceId;

	header("location:sell_space_add_details.php");
	
	}

?>
<table width="100%" class="center" cellspacing="0" cellpadding="0">
<tr>
  <td align="center" valign="top" >
<body id="tab1">
<ul id="tabnav">
  <li class="tab1"><a href="customize_banner.php?sid=<?php echo $_REQUEST['sid'];?>">Build Layout</a></li>
  <li class="tab2"><a href="#">Add Details</a></li>
  <li class="tab3"><a href="#">Get Code</a></li>
</ul>
</body>
<form id="bannerAdSpace" action="" method="post" class="tight-layout" onSubmit="javascript:return validate();">
  <link rel="stylesheet" href="css/adspace.css" type="text/css">
  <script type="text/javascript" language="javascript" src="js.html"></script>
  <script type="text/javascript" src="JavaScripts/common.js"></script>
  <script type="text/javascript" language="javascript" src="JavaScripts/form.js"></script>
  <div id="colorlayer" onMouseOver="javascript:enterColorPalette()" onMouseOut="javascript:leaveColorPalette()" class="drag" style="visibility: hidden; width: 204px; height: 142px; position: absolute; z-index: 4;">
    <table bgcolor="#ffffff" border="0" cellpadding="1" cellspacing="2" width="90%">
      <tbody>
        <tr>
          <td id="selectedcolor" width="12%"></td>
          <td id="colorcode" align="center" width="75%"></td>
          <td width="12%"><div id="transparent" style="cursor: pointer; visibility: inherit;"><img src="images/transparent.gif" onMouseOver="javascript:onTransparent();" onClick="javascript:onClickTransparent();preview();"></div></td>
        </tr>
      </tbody>
    </table>
    <table id="colortable" style="border: 1px solid rgb(127, 157, 185); cursor: pointer; height: 115px;" bgcolor="#ffffff" border="0" cellpadding="1" cellspacing="2" width="100%">
      <tbody></tbody>
    </table>
    <iframe src="blank_003.html" style="position: absolute; visibility: inherit; top: 0px; left: 0px; width: 204px; height: 142px; z-index: -1;" frameborder="0"></iframe>
  </div>
  <script language="javascript" type="text/javascript">
<!--
    var transparent = "label_text_transparent";

    var ns = document.getElementById&&!document.all; //boolean flag for netscape/firefox
    var objId; //object id
    var selected; //selected color
    var onchangeFlag = false;
    init();

    //Initialize the color table.
    function init() {
        var colors = new Array (
            ['#FF8080', '#FFFF80', '#80FF80', '#00FF80', '#80FFFF', '#0080FF', '#FF80C0', '#FF80FF'],
            ['#FF0000', '#FFFF00', '#80FF00', '#00FF40', '#00FFFF', '#0080C0', '#8080C0', '#FF00FF'],
            ['#804040', '#FF8040', '#00FF00', '#008080', '#004080', '#8080FF', '#800040', '#FF0080'],
            ['#800000', '#FF8000', '#008000', '#008040', '#0000FF', '#0000A0', '#800080', '#8000FF'],
            ['#400000', '#804000', '#004000', '#004040', '#000080', '#000040', '#400040', '#400080'],
            ['#000000', '#808000', '#808040', '#808080', '#408080', '#C0C0C0', '#400040', '#FFFFFF']
        );
        var table = document.getElementById("colortable");

        for (itr in colors) {
            var row = table.insertRow(-1);
            for (itd in colors[itr]) {
                var cell = row.insertCell(-1);
                cell.height = 17;
                cell.innerText = "";
                cell.bgColor = colors[itr][itd];

                //when move mouse to a cell, the selected color will changed
                cell.onmouseover = function() {
                    var colorcode = document.getElementById("colorcode");
                    colorcode.innerHTML = "<b>" + this.bgColor.toUpperCase() + "</b>";
                    var selectedcolor = document.getElementById("selectedcolor");
                    selectedcolor.bgColor = this.bgColor;
                    selected = selectedcolor;
                }
                //when mouse click, the selected color will be assigned to obj
                //and color palette will be closed
                cell.onclick  = function(){
                    if (objId != '') {
                        var obj = document.getElementById(objId);
                    }
                    obj.value = selected.bgColor.toUpperCase();
                    if (obj.onchange) {
                        obj.onchange();
                    }
                    onClickPalette('', null);
                    preview();
                };
            }
        }
    }


    //It is called when mouse over transparent cell
    function onTransparent() {
        var colorcode = document.getElementById("colorcode");
        colorcode.innerHTML = "<b>" + transparent + "</b>";
        var selectedcolor = document.getElementById("selectedcolor");
        selectedcolor.bgColor = "Transparent";
    }


    //It is called when mouseclick on transparent cell
    function onClickTransparent() {
        if (objId != '') {
            var obj = document.getElementById(objId);
        }
        obj.value = 'TRANSPARENT';
        onClickPalette('', null);
    }

    //show or hide the palette
    //it also inits table data and div position
    function onClickPalette(objid, control, isTran, leftTopDisplay) {
        if (!document.all && onchangeFlag) {
            return;
        }
        var l = 0;
        var t = 0;
        var obj;
        if (objid != '') {
            obj = document.getElementById(objid);
            objId = objid;
        }

        //check that needs the transparent or not
        var transparent = document.getElementById("transparent");
        if (typeof(isTran) != "undefined") {
            transparent.style.visibility = (isTran) ? "inherit" : "hidden";
        }
        else {
            transparent.style.visibility = "hidden";
        }

        //calculate the control position
        if (control != null) {
            controlTop = control.offsetTop;
            controlLeft = control.offsetLeft + 20;
            while(control = control.offsetParent) {
                controlTop += control.offsetTop;
                controlLeft += control.offsetLeft;
            }
        }

        //init div position
        var div = document.getElementById('colorlayer');
        if (leftTopDisplay != null) {
            leftDistance = controlLeft - div.offsetWidth;
            topDistance = controlTop - div.offsetHeight;
            div.style.left = leftDistance + "px";
            div.style.top = topDistance + "px";
        }
        else {
            div.style.left = controlLeft + "px";
            div.style.top = controlTop + "px";
        }

        //init div data
        if (div.style.visibility == 'hidden') {
            var selectedcolor = document.getElementById('selectedcolor');
            selectedcolor.bgColor = obj.value;
            var colorcode = document.getElementById('colorcode');
            colorcode.innerHTML = "<b>" + obj.value.toUpperCase() + "</b>";
        }

        div.style.visibility = (div.style.visibility == 'hidden') ? 'visible' : 'hidden';
    }

    var inColorPalette = false;
    function mousedown() {
        if (!inColorPalette) {
            var div = document.getElementById('colorlayer');
            div.style.visibility = 'hidden';
        }
    }

    function leaveColorPalette() {
        inColorPalette=false;
    }

    function enterColorPalette() {
        inColorPalette=true;
    }

    document.onmousedown = mousedown;

-->
</script>
  <table  align="center" width="85%">
    <tbody>
      <tr valign="top">
        <td style="width: 50%;"><table style="background-color: rgb(153, 153, 153); width: 100%;" cellpadding="3" cellspacing="1" class="mainTable">
            <tbody>
              <tr>
                <td style="text-align: left; color: rgb(255, 255, 255); font-weight: bold;" class="sitename">Ad Space Characteristics</td>
              </tr>
              <tr style="background-color: rgb(251, 251, 251);">
                <td>
    <div style="padding: 3px; text-align: left;">
        <table style="text-align: left;" align="center" width="100%">
            <tbody>
                <tr>
                    <td colspan="2" class="blackbold" style="text-align: left;">
                        Ad Space Type:
                        <select id="adspaceType" name="adspace_type" class="flat blackbold">
                            <option value="text" onclick="window.location='customize_ad.php'">Text</option>
                            <option value="banner" selected="selected" onclick="window.location='customize_banner.php'">
                                Banner</option>
                            <option value="thumbnail" onclick="window.location='customize_thumbnail.php'">Thumbnail</option>
                            <option value="customize_commBreak" onclick="window.location='customize_commBreak.php'">
                                Commercial Break</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <hr>
                    </td>
                </tr>
                <tr>
                    <td>
                        Choose a Web Site:
                    </td>
                    <td>
                        <select id="siteId" name="site_id" class="flat" onchange="changeRating();">
                            <option label="Please Select" value="0" selected="selected">Please Select</option>
                            <?php while($fetSiteUrl=mysql_fetch_array($selSiteurl)) { ?>
                            <option label="<?=$fetSiteUrl['adSiteUrl']?>" value="<?=$fetSiteUrl['adsiteId']?>"><?=$fetSiteUrl['adSiteUrl']?>
                            </option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        Size:
                    </td>
                    <td>
                        <select id="size" name="size" onchange="javascrip: preview();window.changed = true;">
                            <option label="Vertical Banner (120 x 240)" value="120x240" selected="selected">Vertical
                                Banner (120 x 240)</option>
                            <option label="Mini Skyscraper(120 x 400)" value="120x400">Mini Skyscraper(120 x 400)</option>
                            <option label="Skyscraper (120 x 600)" value="120x600">Skyscraper (120 x 600)</option>
                            <option label="Square Button (125 x 125)" value="125x125">Square Button (125 x 125)</option>
                            <option label="Wide Skyscraper1 (150 x 600)" value="150x600">Wide Skyscraper1 (150 x
                                600)</option>
                            <option label="Wide Skyscraper2 (160 x 600)" value="160x600">Wide Skyscraper2 (160 x
                                600)</option>
                            <option label="Wide Skyscraper3 (200 x 480)" value="200x480">Wide Skyscraper3 (200 x
                                480)</option>
                            <option label="Square (250 x 250)" value="250x250">Square (250 x 250)</option>
                            <option label="Medium Rectangle (300 x 250)" value="300x250">Medium Rectangle (300 x
                                250)</option>
                            <option label="Medium Rectangle 2 (300 x 210)" value="300x210">Medium Rectangle 2 (300
                                x 210)</option>
                            <option label="Medium Rectangle 3 (400 x 250)" value="400x250">Medium Rectangle 3 (400
                                x 250)</option>
                            <option label="Full Banner (468 x 60)" value="468x60">Full Banner (468 x 60)</option>
                            <option label="Leader Board (728 x 90)" value="728x90">Leader Board (728 x 90)</option>
                            <option label="Large Leader Board (728 x 300)" value="728x300">Large Leader Board (728
                                x 300)</option>
                            <option label="Large Leader Board 2 (768 x 245)" value="768x245">Large Leader Board
                                2 (768 x 245)</option>
                        </select>
                    </td>
                </tr>
                <!--######################### code on 25_07_09 starts####################-->
                <tr>
                    <td>
                        #Ads Type:
                    </td>
                    <td>
                        <select id="ad_Type" name="ad_Type" class="flat">
                            <option label="direct" value="direct" selected="selected">Direct</option>
                            <option label="network" value="network">Network</option>
                        </select>
                    </td>
                </tr>
                <!--######################### code on 25_07_09 ends #####################-->
                <tr>
                    <td colspan="2">
                        <div style="font-weight: bold; color: rgb(0, 0, 0);">
                            Template Appearance</div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input id="use_template" name="template_setting" value="off" onclick="setTemplateAppearance(false);"
                            checked="true" type="radio">
                        <label for="use_template">
                            Use Template Setting</label>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input id="config_appearance" name="template_setting" value="on" onclick="setTemplateAppearance(true);"
                            type="radio">
                        <label for="config_appearance">
                            Configure Appearance</label>
                    </td>
                </tr>
            </tbody>
        </table>
        <table id="configAppearanceTable" style="width: 330px; display: none;">
            <tbody>
                <tr>
                    <td style="width: 29%;">
                        Background Color:
                    </td>
                    <td style="width: 36%;">
                        <input id="backgroundColor" name="background_color" class="flat" size="10" maxlength="10"
                            value="" onchange="window.changed = true;changeStyle('color', this, 'previewBackgroundColor');"
                            type="text">
                        <a class="">Background Color</a><img style="cursor: pointer; padding-left: 3px;"
                            src="images/palette.gif" alt="label_text_palette" onclick="javascript: onClickPalette('backgroundColor', this, false);">
                    </td>
                    <td style="width: 35%;">
                        <div id="previewBackgroundColor" style="height: 18px;">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        Header:
                    </td>
                </tr>
                <tr>
                    <td style="padding-left: 20px;">
                        Font Type:
                    </td>
                    <td colspan="2">
                        <select id="headerFontType" class="flat" name="header_font_type" onchange="window.changed = true;changeStyle('fontType', this, 'previewHeaderStyle');">
                            <option label="Arial" value="Arial">Arial</option>
                            <option label="Georgia" value="Georgia">Georgia</option>
                            <option label="Sans-serif" value="MS Sans Serif">Sans-serif</option>
                            <option label="Times" value="Times">Times</option>
                            <option label="Verdana" value="Verdana">Verdana</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="padding-left: 20px;">
                        Color:
                    </td>
                    <td>
                        <input id="headerColor" name="header_bg_color" class="flat" size="10" maxlength="10"
                            value="" onchange="window.changed = true;changeStyle('color', this, 'previewHeaderStyle');"
                            type="text">
                        <a class="">Color</a><img style="cursor: pointer; padding-left: 3px;" src="images/palette.gif"
                            alt="label_text_palette" onclick="onClickPalette('headerColor', this, false);">
                    </td>
                    <td>
                        <div id="previewHeaderStyle" style="height: 18px; padding-left: 5px; font-family: arial;">
                            Header Sample</div>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        Body:
                    </td>
                </tr>
                <tr>
                    <td style="padding-left: 20px;">
                        Font Type:
                    </td>
                    <td colspan="2">
                        <select id="bodyFontType" class="flat" name="body_font_type" onchange="window.changed = true;changeStyle('fontType', this, 'previewBodyStyle');">
                            <option label="Arial" value="Arial">Arial</option>
                            <option label="Georgia" value="Georgia">Georgia</option>
                            <option label="Sans-serif" value="MS Sans Serif">Sans-serif</option>
                            <option label="Times" value="Times">Times</option>
                            <option label="Verdana" value="Verdana">Verdana</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="padding-left: 20px;">
                        Color:
                    </td>
                    <td>
                        <input id="bodyColor" name="body_bg_color" class="flat" size="10" maxlength="10"
                            value="" onchange="window.changed = true;changeStyle('color', this, 'previewBodyStyle');"
                            type="text">
                        <a class="">Color</a><img style="cursor: pointer; padding-left: 3px;" src="images/palette.gif"
                            alt="label_text_palette" onclick="javascript: onClickPalette('bodyColor', this, false);">
                    </td>
                    <td>
                        <div id="previewBodyStyle" style="height: 18px; padding-left: 5px; font-family: arial;">
                            Body Sample</div>
                    </td>
                </tr>
            </tbody>
        </table>
        <div style="padding-top: 10px; padding-bottom: 10px; font-weight: bold;">
            Note: If this banner ad space does not have a direct ad campaign running, a banner
            template will be used that will display text ads, thumbnail ads and/or banner ads
            from our network.</div>
    </div>
</td>
              </tr>
            </tbody>
          </table>
          <div style="text-align: right; padding-top: 10px;">
            <input id="dimensionChanged" name="dimension_changed" value="false" type="hidden">
            <input name="back" value="Back" class="blank-button-small" onClick="javascript: void();" type="button">
            <input name="next" value="Next" class="yellow-button-small" type="submit">
          </div></td>
		   <td>&nbsp;</td>
        <td style="width: 50%;"><table style="background-color: rgb(153, 153, 153); width: 100%;" cellpadding="3" cellspacing="1">
            <tbody>
              <tr>
                <td style="text-align: left; color: rgb(255, 255, 255); font-weight: bold;" class="sitename">Preview</td>
              </tr>
              <tr style="background-color: rgb(251, 251, 251);">
                <td><div style="padding: 3px; text-align: left;">
                    <div id="bannerPreview">
                      <div><img id="bannerImage" style="border: 1px solid rgb(127, 157, 185); width: 120px; height: 240px;" src="images/ad_test_120x240.jpg" alt="Banner Test" height="240" width="120"></div>
                    </div>
                  </div></td>
              </tr>
            </tbody>
          </table></td>
      </tr>
    </tbody>
  </table>
 <script language="javascript" type="text/javascript">
<!--

var confirm_hide_link = "Are you sure? If you hide the link, people will not be able to advertise on your site or become your affiliate.";
var alert_choose_website = "Please choose a website from the dropdown list";
var alert_same_header_color_and_background_color = "The background color and header color should not be the same.";
var alert_same_body_color_and_background_color = "The background color and body color should not be the same.";
var leave_message = "Do you want to save your changes?";
var image_path = "images/";
//var location_url = 'selling-adspace-list.php?sid=2d47b082c2e464ec257bb48468c0ddfb';
var old_size = "120x240";
var old_broker_hide = "No";
var confirm_edit_dimension_change = "The dimensions of this Ad Space have changed. If you are using Iframe Mode Ad Space Code, you will need to copy the new code and include it on your website in order for the dimensions appear correctly.";
var is_edit = false;

var changed = false;

function setTemplateAppearance(configAppearance) {
    if (configAppearance) {
        var configAppearanceTable = document.getElementById('configAppearanceTable');
        configAppearanceTable.style.display = 'block';
        var inputs = configAppearanceTable.getElementsByTagName('input');
        for (var i = 0; i < inputs.length; i++) {
            if ('text' == inputs[i].type) {
                nextSibling = inputs[i].nextSibling;
                if ((nextSibling != null) && (nextSibling.nodeType == 1) && (nextSibling.tagName == "A")){
                    nextSibling.className = 'colorformat';
                }
            }
        }
    }
    else {
        var configAppearanceTable = document.getElementById('configAppearanceTable');
        configAppearanceTable.style.display = 'none';
        var inputs = configAppearanceTable.getElementsByTagName('input');
        for (var i = 0; i < inputs.length; i++) {
            if ('text' == inputs[i].type) {
                nextSibling = inputs[i].nextSibling;
                if ((nextSibling != null) && (nextSibling.nodeType == 1) && (nextSibling.tagName == "A")){
                    nextSibling.className = '';
                }
            }
        }
    }
}

function changeStyle(type, srcElement, destElementName) {
    if ('color' == type) {
        var color = srcElement.value;
        if ('backgroundColor' == srcElement.id) {
            document.getElementById('previewBackgroundColor').style.backgroundColor = color;
            document.getElementById('previewHeaderStyle').style.backgroundColor = color;
            document.getElementById('previewBodyStyle').style.backgroundColor = color;
        }
        else {
            document.getElementById(destElementName).style.color = color;
        }
    }
    else if ('fontType' == type) {
        var fontType = srcElement.value;
        document.getElementById(destElementName).style.fontFamily = fontType;
    }
}

function processBack() {
    if (checkChange(changed, leave_message)) {
        window.location.href = location_url;
    }
}


function preview() {
    var image = document.getElementById("bannerImage");
    var sizeObject = document.getElementById("size");
    
    var size = document.getElementById("size").value;
    var sizes = size.split("x");
    var width = sizes[0];
    var height = sizes[1];

    image.style.width = width + "px";
    image.style.height = height+ "px";
    image.src = image_path + "ad_test_" + size + ".jpg";

    if (isIE7()) {
        controlIE7Performance();
    }

}

function validate() {
    var result = true;
    var objSite = document.getElementById("siteId");
    var result2 = true;
    if (null != objSite) {
        if ("0" == objSite.value) {
            alert(alert_choose_website);
            objSite.focus();
            return false;
        }
    }
    result = validateForm(document.getElementById("bannerAdSpace"));
    if (result == false) {
        return false;
    }
    if (result && document.getElementById('config_appearance').checked) {
        bgColor = document.getElementById('backgroundColor').value;
        headerColor = document.getElementById('headerColor').value;
        bodyColor = document.getElementById('bodyColor').value;
        if (bgColor == headerColor) {
            alert(alert_same_header_color_and_background_color);
            document.getElementById('headerColor').focus();
            result = false;
        }
        else if (bgColor == bodyColor) {
            alert(alert_same_body_color_and_background_color);
            document.getElementById('bodyColor').focus();
            result = false;
        }
    }

    return result && result2;
}
preview();

var oldOnload = window.onload;
window.onload = function() {
    if (oldOnload) {
        oldOnload();
    }
    if (isIE7()) {
        controlIE7Performance();
    }
    if (document.getElementById('config_appearance').checked) {
        setTemplateAppearance(true);
    }
}

-->
</script>
</form>
</td>
</tr>
</table>
<?php
}
?>
